﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Checkers
{
    internal class CheckerBoard
    {
        internal static int checkerBoardSize = 8;

        internal CheckerPiece[,] checkerBoard { get; set; }
        internal Player currentPlayersTurn { get; set; }

        internal CheckerBoard()
        {
            this.checkerBoard = GetStartingCheckerBoard(CheckerBoard.checkerBoardSize);
            this.currentPlayersTurn = Player.Red;
        }

        private CheckerPiece[,] GetStartingCheckerBoard(int checkerBoardSize)
        {
            CheckerPiece[,] checkerBoard = new CheckerPiece[checkerBoardSize, checkerBoardSize];

            for (int row = 0; row < checkerBoard.GetLength(0); ++row)
            {
                for (int column = 0; column < checkerBoard.GetLength(1); ++column)
                {
                    if (row % 2 == 0)
                    {
                        if (column % 2 == 0)
                        {
                            checkerBoard[row, column] = CheckerPiece.Invalid;
                        }
                        else
                        {
                            if (row <= 2)
                                checkerBoard[row, column] = CheckerPiece.BlackReg;
                            else if (row >= 5)
                                checkerBoard[row, column] = CheckerPiece.RedReg;
                            else
                                checkerBoard[row, column] = CheckerPiece.Empty;
                        }
                    }
                    else
                    {
                        if (column % 2 == 0)
                        {
                            if (row <= 2)
                                checkerBoard[row, column] = CheckerPiece.BlackReg;
                            else if (row >= 5)
                                checkerBoard[row, column] = CheckerPiece.RedReg;
                            else
                                checkerBoard[row, column] = CheckerPiece.Empty;
                        }
                        else
                        {
                            checkerBoard[row, column] = CheckerPiece.Invalid;
                        }
                    }
                }
            }

            return checkerBoard;
        }

        internal Player GetPlayer(CheckerPiece checkerPiece)
        {
            Player player;

            switch (checkerPiece)
            {
                case CheckerPiece.BlackKing:
                    player = Player.Black;
                    break;
                case CheckerPiece.BlackReg:
                    player = Player.Black;
                    break;
                case CheckerPiece.RedKing:
                    player = Player.Red;
                    break;
                case CheckerPiece.RedReg:
                    player = Player.Red;
                    break;
                default:
                    player = Player.Invalid;
                    break;
            }

            return player;
        }

        internal bool IsThisPlayerTurn(Point cellPosition)
        {
            CheckerPiece playerClicked = this.checkerBoard[cellPosition.row, cellPosition.column];

            if (this.currentPlayersTurn == this.GetPlayer(playerClicked))
                return true;
            else
                return false;
        }

        internal Possible_Move[] GetAvailableMoves(Point point, Boolean firstMove)
        {
            List<Possible_Move> moves = new List<Possible_Move>();


            //determin enumerator for position "point" on the checkerboard
            int enumerator = (int)checkerBoard[point.row, point.column];

            //check if it is first move
            if (firstMove == true) // second move
            {
                //if the piece is red
                if (enumerator == 1 || enumerator == 3) //piece is red
                {
                    if (enumerator == 1) //red piece is normal
                    {
                        if (point.row - 2 >= 0 && point.column + 2 <= 7)//check normal red right jump
                        {
                            if (checkerBoard[point.row - 2, point.column + 2] == 0)
                            {
                                if ((int)checkerBoard[point.row - 1, point.column + 1] == 2 || (int)checkerBoard[point.row - 1, point.column + 1] == 4)//test whether the piece being juped is black
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row - 1, point.column + 1] = CheckerPiece.Empty;
                                    if ((point.row - 2) != 0)
                                        jump_topRight.board[point.row - 2, point.column + 2] = CheckerPiece.RedReg;
                                    else jump_topRight.board[point.row - 2, point.column + 2] = CheckerPiece.RedKing;
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row - 2;
                                    jump_topRight.piece.column = point.column + 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }

                        if (point.row - 2 >= 0 && point.column - 2 >= 0)//check normal red piece left jump
                        {
                            if (checkerBoard[point.row - 2, point.column - 2] == 0)
                            {
                                if ((int)checkerBoard[point.row - 1, point.column - 1] == 2 || (int)checkerBoard[point.row - 1, point.column - 1] == 4)//test whether the piece being juped is black
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row - 1, point.column - 1] = CheckerPiece.Empty;
                                    if ((point.row - 2) != 0)
                                        jump_topRight.board[point.row - 2, point.column - 2] = CheckerPiece.RedReg;
                                    else jump_topRight.board[point.row - 2, point.column - 2] = CheckerPiece.RedKing;
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row - 2;
                                    jump_topRight.piece.column = point.column - 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }
                    }
                    else //red piece is a king
                    {
                        if (point.row - 2 >= 0 && point.column + 2 <= 7)//check red king right top jump
                        {
                            if (checkerBoard[point.row - 2, point.column + 2] == 0)
                            {
                                if ((int)checkerBoard[point.row - 1, point.column + 1] == 2 || (int)checkerBoard[point.row - 1, point.column + 1] == 4)//test whether the piece being juped is black
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row - 1, point.column + 1] = CheckerPiece.Empty;
                                    if ((point.row - 2) != 0)
                                        jump_topRight.board[point.row - 2, point.column + 2] = CheckerPiece.RedReg;
                                    else jump_topRight.board[point.row - 2, point.column + 2] = CheckerPiece.RedKing;
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row - 2;
                                    jump_topRight.piece.column = point.column + 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }

                        if (point.row - 2 >= 0 && point.column - 2 >= 0 && point.column + 2 <= 7)//check red king piece left top jump
                        {
                            if (checkerBoard[point.row - 2, point.column + 2] == 0)
                            {
                                if ((int)checkerBoard[point.row - 1, point.column + 1] == 2 || (int)checkerBoard[point.row - 1, point.column + 1] == 4)//test whether the piece being juped is black
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row - 1, point.column + 1] = CheckerPiece.Empty;
                                    jump_topRight.board[point.row - 2, point.column + 2] = CheckerPiece.RedKing;
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row - 2;
                                    jump_topRight.piece.column = point.column + 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }

                        if (point.row + 2 <= 7 && point.column + 2 <= 7)//test red king bottom right jump
                        {
                            if (checkerBoard[point.row + 2, point.column + 2] == 0)
                            {
                                if ((int)checkerBoard[point.row + 1, point.column + 1] == 2 || (int)checkerBoard[point.row + 1, point.column + 1] == 4)//test whether the piece being jumped is black
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row + 1, point.column + 1] = CheckerPiece.Empty;
                                    jump_topRight.board[point.row + 2, point.column + 2] = CheckerPiece.RedKing;
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row + 2;
                                    jump_topRight.piece.column = point.column + 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }

                        if (point.row + 2 <= 7 && point.column - 2 >= 0)//test red king bottom left jump
                        {
                            if (checkerBoard[point.row + 2, point.column - 2] == 0)
                            {
                                if ((int)checkerBoard[point.row + 1, point.column - 1] == 2 || (int)checkerBoard[point.row + 1, point.column - 1] == 4)//test whether the piece being juped is black
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row + 1, point.column - 1] = CheckerPiece.Empty;
                                    jump_topRight.board[point.row + 2, point.column - 2] = CheckerPiece.RedKing;
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row + 2;
                                    jump_topRight.piece.column = point.column - 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }

                    }

                }
                else //piece is black
                {
                    if (enumerator == 2) //red piece is normal
                    {
                        if (point.row + 2 <= 7 && point.column + 2 <= 7)//check normal black right jump
                        {
                            if (checkerBoard[point.row + 2, point.column + 2] == 0)
                            {
                                if ((int)checkerBoard[point.row + 1, point.column + 1] == 1 || (int)checkerBoard[point.row + 1, point.column + 1] == 3)//test whether the piece being juped is red
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row + 1, point.column + 1] = CheckerPiece.Empty;
                                    if ((point.row + 2) != 7)
                                        jump_topRight.board[point.row + 2, point.column + 2] = CheckerPiece.BlackReg;
                                    else jump_topRight.board[point.row + 2, point.column + 2] = CheckerPiece.BlackKing;
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row + 2;
                                    jump_topRight.piece.column = point.column + 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }

                        if (point.row + 2 <= 7 && point.column - 2 >= 0)//check normal black piece left jump
                        {
                            if (checkerBoard[point.row + 2, point.column - 2] == 0)
                            {
                                if ((int)checkerBoard[point.row + 1, point.column - 1] == 1 || (int)checkerBoard[point.row + 1, point.column - 1] == 3)//test whether the piece being juped is red
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row + 1, point.column - 1] = CheckerPiece.Empty;
                                    if ((point.row + 2) != 7)
                                        jump_topRight.board[point.row + 2, point.column - 2] = CheckerPiece.BlackReg;
                                    else jump_topRight.board[point.row + 2, point.column - 2] = CheckerPiece.BlackKing;
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row + 2;
                                    jump_topRight.piece.column = point.column - 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }
                    }
                    else //black piece is a king
                    {
                        if (point.row - 2 >= 0 && point.column + 2 <= 7)//check black king right top jump
                        {
                            if (checkerBoard[point.row - 2, point.column + 2] == 0)
                            {
                                if ((int)checkerBoard[point.row - 1, point.column + 1] == 1 || (int)checkerBoard[point.row - 1, point.column + 1] == 3)//test whether the piece being juped is red
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row - 1, point.column + 1] = CheckerPiece.Empty;
                                    if ((point.row - 2) != 0)
                                        jump_topRight.board[point.row - 2, point.column + 2] = CheckerPiece.BlackReg;
                                    else jump_topRight.board[point.row - 2, point.column + 2] = CheckerPiece.BlackKing;
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row - 2;
                                    jump_topRight.piece.column = point.column + 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }

                        if (point.row - 2 >= 0 && point.column - 2 >= 0)//check black king piece left top jump
                        {
                            if (checkerBoard[point.row - 2, point.column - 2] == 0)
                            {
                                if ((int)checkerBoard[point.row - 1, point.column - 1] == 1 || (int)checkerBoard[point.row - 1, point.column - 1] == 3)//test whether the piece being juped is red
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row - 1, point.column - 1] = CheckerPiece.Empty;
                                    jump_topRight.board[point.row - 2, point.column - 2] = CheckerPiece.BlackKing;
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row - 2;
                                    jump_topRight.piece.column = point.column + 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }

                        if (point.row + 2 <= 7 && point.column + 2 <= 7)//test black king bottom right jump
                        {
                            if (checkerBoard[point.row + 2, point.column + 2] == 0)
                            {
                                if ((int)checkerBoard[point.row + 1, point.column + 1] == 1 || (int)checkerBoard[point.row + 1, point.column + 1] == 3)//test whether the piece being jumped is red
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row + 1, point.column + 1] = CheckerPiece.Empty;
                                    jump_topRight.board[point.row + 2, point.column + 2] = CheckerPiece.BlackKing;
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row + 2;
                                    jump_topRight.piece.column = point.column + 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }

                        if (point.row + 2 <= 7 && point.column - 2 >= 0)//test black king bottom left jump
                        {
                            if (checkerBoard[point.row + 2, point.column - 2] == 0)
                            {
                                if ((int)checkerBoard[point.row + 1, point.column - 1] == 1 || (int)checkerBoard[point.row + 1, point.column - 1] == 3)//test whether the piece being juped is red
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row + 1, point.column - 1] = CheckerPiece.Empty;
                                    jump_topRight.board[point.row + 2, point.column - 2] = CheckerPiece.BlackKing;
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row + 2;
                                    jump_topRight.piece.column = point.column - 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }
                    }
                }

            }
            else // first move
            {
                //if the piece is red
                if (enumerator == 1 || enumerator == 3) //piece is red
                {
                    if (enumerator == 1) //red piece is normal
                    {
                        if (point.row - 1 >= 0 && point.column + 1 <= 7)//check normal red right 
                        {

                            if ((int)checkerBoard[point.row - 1, point.column + 1] == 0 || (int)checkerBoard[point.row - 1, point.column + 1] == 0)//test whether the adjacent square is empty
                            {
                                Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                if ((point.row - 1) != 0)
                                    jump_topRight.board[point.row - 1, point.column + 1] = CheckerPiece.RedReg;
                                else jump_topRight.board[point.row - 1, point.column + 1] = CheckerPiece.RedKing;
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.proceed = false;
                                jump_topRight.piece.row = point.row - 1;
                                jump_topRight.piece.column = point.column + 1;
                                moves.Add(jump_topRight);
                            }

                        }

                        if (point.row - 1 >= 0 && point.column - 1 >= 0)//check normal red piece left
                        {

                            if ((int)checkerBoard[point.row - 1, point.column - 1] == 0 || (int)checkerBoard[point.row - 1, point.column - 1] == 0)//test whether adjacent square is empty
                            {
                                Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                if ((point.row - 1) != 0)
                                    jump_topRight.board[point.row - 1, point.column - 1] = CheckerPiece.RedReg;
                                else jump_topRight.board[point.row - 1, point.column - 1] = CheckerPiece.RedKing;
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.proceed = false;
                                jump_topRight.piece.row = point.row - 1;
                                jump_topRight.piece.column = point.column - 1;
                                moves.Add(jump_topRight);
                            }
                        }
                        //test if adjacent piece can be jumped
                        if (point.row - 2 >= 0 && point.column + 2 <= 7)//check normal red right jump
                        {
                            if (checkerBoard[point.row - 2, point.column + 2] == 0)
                            {

                                if ((int)checkerBoard[point.row - 1, point.column + 1] == 2 || (int)checkerBoard[point.row - 1, point.column + 1] == 4)//test whether the adjacent square is empty
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    if ((point.row - 2) != 0)
                                        jump_topRight.board[point.row - 2, point.column + 2] = CheckerPiece.RedReg;
                                    else jump_topRight.board[point.row - 2, point.column + 2] = CheckerPiece.RedKing;
                                    jump_topRight.board[point.row - 1, point.column + 1] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row - 2;
                                    jump_topRight.piece.column = point.column + 2;
                                    moves.Add(jump_topRight);
                                }

                            }
                        }

                        if (point.row - 2 >= 0 && point.column - 2 >= 0)//check normal red piece left jump
                        {
                            if (checkerBoard[point.row - 2, point.column - 2] == 0)
                            {
                                if ((int)checkerBoard[point.row - 1, point.column - 1] == 2 || (int)checkerBoard[point.row - 1, point.column - 1] == 4)//test whether adjacent square is empty
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    if ((point.row - 2) != 0)
                                        jump_topRight.board[point.row - 2, point.column - 2] = CheckerPiece.RedReg;
                                    else jump_topRight.board[point.row - 2, point.column - 2] = CheckerPiece.RedKing;
                                    jump_topRight.board[point.row - 1, point.column - 1] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row - 2;
                                    jump_topRight.piece.column = point.column - 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }
                    }

                    else //red piece is a king
                    {
                        //red king right top and left top
                        if (point.row - 1 >= 0 && point.column + 1 <= 7)//check normal red right 
                        {

                            if ((int)checkerBoard[point.row - 1, point.column + 1] == 0 || (int)checkerBoard[point.row - 1, point.column + 1] == 0)//test whether the adjacent square is empty
                            {
                                Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.board[point.row - 1, point.column + 1] = CheckerPiece.RedKing;
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.proceed = false;
                                jump_topRight.piece.row = point.row - 1;
                                jump_topRight.piece.column = point.column + 1;
                                moves.Add(jump_topRight);
                            }

                        }

                        if (point.row - 1 >= 0 && point.column - 1 >= 0)//check normal red piece left
                        {

                            if ((int)checkerBoard[point.row - 1, point.column - 1] == 0 || (int)checkerBoard[point.row - 1, point.column - 1] == 0)//test whether adjacent square is empty
                            {
                                Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.board[point.row - 1, point.column - 1] = CheckerPiece.RedKing;
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.proceed = false;
                                jump_topRight.piece.row = point.row - 1;
                                jump_topRight.piece.column = point.column - 1;
                                moves.Add(jump_topRight);
                            }
                        }

                        //king bottom right and bottom left
                        if (point.row + 1 >= 0 && point.column + 1 <= 7)//check king bottom right 
                        {

                            if ((int)checkerBoard[point.row + 1, point.column + 1] == 0 || (int)checkerBoard[point.row + 1, point.column + 1] == 0)//test whether the adjacent square is empty
                            {
                                Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.board[point.row + 1, point.column + 1] = CheckerPiece.RedKing;
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.proceed = false;
                                jump_topRight.piece.row = point.row + 1;
                                jump_topRight.piece.column = point.column + 1;
                                moves.Add(jump_topRight);
                            }

                        }

                        if (point.row + 1 <= 7 && point.column - 1 >= 0)//check king piece left
                        {

                            if ((int)checkerBoard[point.row + 1, point.column - 1] == 0 || (int)checkerBoard[point.row + 1, point.column - 1] == 0)//test whether adjacent square is empty
                            {
                                Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.board[point.row + 1, point.column - 1] = CheckerPiece.RedKing;
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.proceed = false;
                                jump_topRight.piece.row = point.row + 1;
                                jump_topRight.piece.column = point.column - 1;
                                moves.Add(jump_topRight);
                            }
                        }

                        //king top right and top left jump
                        //test if adjacent piece can be jumped
                        if (point.row - 2 >= 0 && point.column + 2 <= 7)//check normal red right jump
                        {
                            if (checkerBoard[point.row - 2, point.column + 2] == 0)
                            {

                                if ((int)checkerBoard[point.row - 1, point.column + 1] == 2 || (int)checkerBoard[point.row - 1, point.column + 1] == 4)//test whether the adjacent square is empty
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.board[point.row - 2, point.column + 2] = CheckerPiece.RedKing;
                                    jump_topRight.board[point.row - 1, point.column + 1] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row - 2;
                                    jump_topRight.piece.column = point.column + 2;
                                    moves.Add(jump_topRight);
                                }

                            }
                        }

                        if (point.row - 2 >= 0 && point.column - 2 >= 0)//check normal red piece left jump
                        {
                            if (checkerBoard[point.row - 2, point.column - 2] == 0)
                            {
                                if ((int)checkerBoard[point.row - 1, point.column - 1] == 2 || (int)checkerBoard[point.row - 1, point.column - 1] == 4)//test whether adjacent square is empty
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.board[point.row - 2, point.column - 2] = CheckerPiece.RedKing;
                                    jump_topRight.board[point.row - 1, point.column - 1] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row - 2;
                                    jump_topRight.piece.column = point.column - 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }

                        //red king left bottom and right bottom jump
                        //test if adjacent piece can be jumped
                        if (point.row + 2 <= 7 && point.column + 2 <= 7)//check normal black right jump
                        {
                            if (checkerBoard[point.row + 2, point.column + 2] == 0)
                            {

                                if ((int)checkerBoard[point.row + 1, point.column + 1] == 2 || (int)checkerBoard[point.row + 1, point.column + 1] == 4)//test whether the adjacent square black
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.board[point.row + 2, point.column + 2] = CheckerPiece.RedKing;
                                    jump_topRight.board[point.row + 1, point.column + 1] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row + 2;
                                    jump_topRight.piece.column = point.column + 2;
                                    moves.Add(jump_topRight);
                                }

                            }
                        }

                        if (point.row + 2 <= 7 && point.column - 2 >= 0)//check normal black piece left jump
                        {
                            if (checkerBoard[point.row + 2, point.column - 2] == 0)
                            {
                                if ((int)checkerBoard[point.row + 1, point.column - 1] == 2 || (int)checkerBoard[point.row + 1, point.column - 1] == 4)//test whether adjacent square is black
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.board[point.row + 2, point.column - 2] = CheckerPiece.RedKing;
                                    jump_topRight.board[point.row + 1, point.column - 1] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row + 2;
                                    jump_topRight.piece.column = point.column - 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }

                    }
                }

                else //piece is black
                {
                    if (enumerator == 2) //black piece is normal
                    {
                        if (point.row + 1 >= 0 && point.column + 1 <= 7)//check normal black right 
                        {

                            if ((int)checkerBoard[point.row + 1, point.column + 1] == 0 || (int)checkerBoard[point.row + 1, point.column + 1] == 0)//test whether the adjacent square is empty
                            {
                                Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                if ((point.row + 1) != 7)
                                    jump_topRight.board[point.row + 1, point.column + 1] = CheckerPiece.BlackReg;
                                else jump_topRight.board[point.row + 1, point.column + 1] = CheckerPiece.BlackKing;
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.proceed = false;
                                jump_topRight.piece.row = point.row + 1;
                                jump_topRight.piece.column = point.column + 1;
                                moves.Add(jump_topRight);
                            }

                        }

                        if (point.row + 1 <= 7 && point.column - 1 >= 0)//check normal black piece left
                        {

                            if ((int)checkerBoard[point.row + 1, point.column - 1] == 0 || (int)checkerBoard[point.row + 1, point.column - 1] == 0)//test whether adjacent square is empty
                            {
                                Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                if ((point.row + 1) != 7)
                                    jump_topRight.board[point.row + 1, point.column - 1] = CheckerPiece.BlackReg;
                                else jump_topRight.board[point.row + 1, point.column - 1] = CheckerPiece.BlackKing;
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.proceed = false;
                                jump_topRight.piece.row = point.row + 1;
                                jump_topRight.piece.column = point.column - 1;
                                moves.Add(jump_topRight);
                            }
                        }
                        //test if adjacent piece can be jumped
                        if (point.row + 2 <= 7 && point.column + 2 <= 7)//check normal black right jump
                        {
                            if (checkerBoard[point.row + 2, point.column + 2] == 0)
                            {

                                if ((int)checkerBoard[point.row + 1, point.column + 1] == 1 || (int)checkerBoard[point.row + 1, point.column + 1] == 3)//test whether the adjacent square is empty
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    if ((point.row + 2) != 7)
                                        jump_topRight.board[point.row + 2, point.column + 2] = CheckerPiece.BlackReg;
                                    else jump_topRight.board[point.row + 2, point.column + 2] = CheckerPiece.BlackKing;
                                    jump_topRight.board[point.row + 1, point.column + 1] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row + 2;
                                    jump_topRight.piece.column = point.column + 2;
                                    moves.Add(jump_topRight);
                                }

                            }
                        }

                        if (point.row + 2 <= 7 && point.column - 2 >= 0)//check normal black piece left jump
                        {
                            if (checkerBoard[point.row + 2, point.column - 2] == 0)
                            {
                                if ((int)checkerBoard[point.row + 1, point.column - 1] == 1 || (int)checkerBoard[point.row + 1, point.column - 1] == 3)//test whether adjacent square is empty
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    if ((point.row + 2) != 7)
                                        jump_topRight.board[point.row + 2, point.column - 2] = CheckerPiece.BlackReg;
                                    else jump_topRight.board[point.row + 2, point.column - 2] = CheckerPiece.BlackKing;
                                    jump_topRight.board[point.row + 1, point.column - 1] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row + 2;
                                    jump_topRight.piece.column = point.column - 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }
                    }
                    else //black piece is a king
                    {
                        //black king normal top right and top left
                        if (point.row + 1 <= 7 && point.column + 1 <= 7)//check normal black right 
                        {

                            if ((int)checkerBoard[point.row + 1, point.column + 1] == 0 || (int)checkerBoard[point.row + 1, point.column + 1] == 0)//test whether the adjacent square is empty
                            {
                                Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.board[point.row + 1, point.column + 1] = CheckerPiece.BlackKing;
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.proceed = false;
                                jump_topRight.piece.row = point.row + 1;
                                jump_topRight.piece.column = point.column + 1;
                                moves.Add(jump_topRight);
                            }

                        }

                        if (point.row + 1 <= 7 && point.column - 1 >= 0)//check normal black piece left
                        {

                            if ((int)checkerBoard[point.row + 1, point.column - 1] == 0 || (int)checkerBoard[point.row + 1, point.column - 1] == 0)//test whether adjacent square is empty
                            {
                                Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.board[point.row + 1, point.column - 1] = CheckerPiece.BlackKing;
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.proceed = false;
                                jump_topRight.piece.row = point.row + 1;
                                jump_topRight.piece.column = point.column - 1;
                                moves.Add(jump_topRight);
                            }
                        }

                        //normal black king bottom left and right
                        if (point.row - 1 >= 0 && point.column + 1 <= 7)//check normal black right 
                        {

                            if ((int)checkerBoard[point.row - 1, point.column + 1] == 0 || (int)checkerBoard[point.row - 1, point.column + 1] == 0)//test whether the adjacent square is empty
                            {
                                Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.board[point.row - 1, point.column + 1] = CheckerPiece.BlackKing;
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.proceed = false;
                                jump_topRight.piece.row = point.row - 1;
                                jump_topRight.piece.column = point.column + 1;
                                moves.Add(jump_topRight);
                            }

                        }

                        if (point.row - 1 >= 0 && point.column - 1 >= 0)//check normal black piece left
                        {

                            if ((int)checkerBoard[point.row - 1, point.column - 1] == 0 || (int)checkerBoard[point.row - 1, point.column - 1] == 0)//test whether adjacent square is empty
                            {
                                Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.board[point.row - 1, point.column - 1] = CheckerPiece.BlackKing;
                                jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                jump_topRight.proceed = false;
                                jump_topRight.piece.row = point.row - 1;
                                jump_topRight.piece.column = point.column - 1;
                                moves.Add(jump_topRight);
                            }
                        }

                        //black king top right jump and top left jump
                        //test if adjacent piece can be jumped
                        if (point.row + 2 <= 7 && point.column + 2 <= 7)//check normal black right jump
                        {
                            if (checkerBoard[point.row + 2, point.column + 2] == 0)
                            {

                                if ((int)checkerBoard[point.row + 1, point.column + 1] == 1 || (int)checkerBoard[point.row + 1, point.column + 1] == 3)//test whether the adjacent square is empty
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.board[point.row + 2, point.column + 2] = CheckerPiece.BlackKing;
                                    jump_topRight.board[point.row + 1, point.column + 1] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row + 2;
                                    jump_topRight.piece.column = point.column + 2;
                                    moves.Add(jump_topRight);
                                }

                            }
                        }

                        if (point.row + 2 <= 7 && point.column - 2 >= 0)//check normal black piece left jump
                        {
                            if (checkerBoard[point.row + 2, point.column - 2] == 0)
                            {
                                if ((int)checkerBoard[point.row + 1, point.column - 1] == 1 || (int)checkerBoard[point.row + 1, point.column - 1] == 3)//test whether adjacent square is empty
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.board[point.row + 2, point.column - 2] = CheckerPiece.BlackKing;
                                    jump_topRight.board[point.row + 1, point.column - 1] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row + 2;
                                    jump_topRight.piece.column = point.column - 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }

                        //black king bottom right and left jumps
                        //test if adjacent piece can be jumped
                        if (point.row - 2 >= 0 && point.column + 2 <= 7)//check normal black right jump
                        {
                            if (checkerBoard[point.row - 2, point.column + 2] == 0)
                            {

                                if ((int)checkerBoard[point.row - 1, point.column + 1] == 1 || (int)checkerBoard[point.row - 1, point.column + 1] == 3)//test whether the adjacent square black
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.board[point.row - 2, point.column + 2] = CheckerPiece.BlackKing;
                                    jump_topRight.board[point.row - 1, point.column + 1] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row - 2;
                                    jump_topRight.piece.column = point.column + 2;
                                    moves.Add(jump_topRight);
                                }

                            }
                        }

                        if (point.row - 2 >= 0 && point.column - 2 >= 0)//check normal black piece left jump
                        {
                            if (checkerBoard[point.row - 2, point.column - 2] == 0)
                            {
                                if ((int)checkerBoard[point.row - 1, point.column - 1] == 1 || (int)checkerBoard[point.row - 1, point.column - 1] == 3)//test whether adjacent square is black
                                {
                                    Possible_Move jump_topRight = new Possible_Move((CheckerPiece[,])this.checkerBoard.Clone());
                                    jump_topRight.board[point.row, point.column] = CheckerPiece.Empty;
                                    jump_topRight.board[point.row - 2, point.column - 2] = CheckerPiece.BlackKing;
                                    jump_topRight.board[point.row - 1, point.column - 1] = CheckerPiece.Empty;
                                    jump_topRight.proceed = true;
                                    jump_topRight.piece.row = point.row - 2;
                                    jump_topRight.piece.column = point.column - 2;
                                    moves.Add(jump_topRight);
                                }
                            }
                        }
                    }
                }
            }

            return moves.ToArray();
        }
    }
}